package cn.pli.bike.wxapi;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.handler.UMWXHandler;
import com.umeng.socialize.utils.Log;
import com.umeng.socialize.weixin.view.WXCallbackActivity;

import cn.pli.bike.R;

/**
 * Created by shangdongzhou on 2018/1/24.
 */

public class WXEntryActivity extends WXCallbackActivity {

   /* @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

    }

    @Override
    public void onResp(BaseResp resp) { //在这个方法中处理微信传回的数据
        //形参resp 有下面两个个属性比较重要
        //1.resp.errCode
        //2.resp.transaction则是在分享数据的时候手动指定的字符创,用来分辨是那次分享(参照4.中req.transaction)
        int a=0;
        switch (resp.errCode) { //根据需要的情况进行处理
            case BaseResp.ErrCode.ERR_OK:
                //正确返回
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                Toast.makeText(this, " 用户取消", Toast.LENGTH_SHORT).show();
                //用户取消
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                //认证被否决
                break;
            case BaseResp.ErrCode.ERR_SENT_FAILED:
                //发送失败
                break;
            case BaseResp.ErrCode.ERR_UNSUPPORT:
                //不支持错误
                break;
            case BaseResp.ErrCode.ERR_COMM:
                //一般错误
                break;
            default:
                //其他不可名状的情况
                break;
        }
        finish();
    }

    @Override
    public void onReq(BaseReq req) {
        //......这里是用来处理接收的请求,暂不做讨论
        finish();
    }

    private final String TAG = WXCallbackActivity.class.getSimpleName();
    protected UMWXHandler mWxHandler = null;

    public WXCallbackActivity() {
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        UMShareAPI api = UMShareAPI.get(this.getApplicationContext());
        Log.um("WXCallbackActivity");
        this.mWxHandler = (UMWXHandler)api.getHandler(SHARE_MEDIA.WEIXIN);
        Log.e(this.TAG, "handleid=" + this.mWxHandler);
        this.mWxHandler.onCreate(this.getApplicationContext(), PlatformConfig.getPlatform(SHARE_MEDIA.WEIXIN));
        this.handleIntent(this.getIntent());
    }

    protected void handleIntent(Intent intent) {
        this.mWxHandler.getWXApi().handleIntent(intent, this);
    }

    protected void onNewIntent(Intent paramIntent) {
        Log.d(this.TAG, "### WXCallbackActivity   onNewIntent");
        super.onNewIntent(paramIntent);
        this.setIntent(paramIntent);
        UMShareAPI api = UMShareAPI.get(this.getApplicationContext());
        this.mWxHandler = (UMWXHandler)api.getHandler(SHARE_MEDIA.WEIXIN);
        Log.e(this.TAG, "handleid=" + this.mWxHandler);
        this.mWxHandler.onCreate(this.getApplicationContext(), PlatformConfig.getPlatform(SHARE_MEDIA.WEIXIN));
        this.handleIntent(paramIntent);
    }

    public void onResp(BaseResp resp) {
        if(this.mWxHandler != null && resp != null) {
            try {
                this.mWxHandler.getWXEventHandler().onResp(resp);
            } catch (Exception var3) {
                ;
            }
        }

        this.finish();
    }

    public void onReq(BaseReq req) {
        if(this.mWxHandler != null) {
            this.mWxHandler.getWXEventHandler().onReq(req);
        }

        this.finish();
    }*/

}


